package cn.hy.today;

import java.util.HashMap;
import java.util.Map;

class Solution_2085 {
    public int countWords(String[] words1, String[] words2) {

        Map<String, Integer> freq1 = new HashMap<>();
        Map<String, Integer> freq2 = new HashMap<>();
        int ans = 0;

        for (String s : words1) {
            freq1.put(s, freq1.getOrDefault(s, 0) + 1);
        }
        for (String s : words2) {
            freq2.put(s, freq2.getOrDefault(s, 0) + 1);
        }

        for (String key : freq1.keySet()) {
            if (freq1.get(key) == 1 && freq2.getOrDefault(key, 0) == 1) {
                ans += 1;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution_2085 solution2085 = new Solution_2085();

        String[] a = {"leetcode","is","amazing","as","is"};
        String[] b = {"amazing","leetcode","is"};
        int i = solution2085.countWords(a, b);
    }
}